<?php
namespace App\Service\Limit;

use App\Facade\Redis;

// 限流器
class LimitService
{
    const KEY = 'limit:';
    const TIME = 3;
    
    // 生成 key
    public static function key($name)
    {
        return self::KEY . $name;
    }

    // 验证
    public static function pass($name)
    {
        // 是否缓存中
        return Redis::set(self::key($name), true, ['nx', 'ex' => self::TIME]);
    }
}